package com.wst.wst_server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wst.wst_server.entity.Org;
import com.wst.wst_server.entity.Section;
import com.wst.wst_server.mapper.SectionMapper;
import com.wst.wst_server.service.ISectionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 科室信息 服务实现类
 * </p>
 *
 * @author zyk
 * @since 2023-03-24
 */
@Service
public class SectionServiceImpl extends ServiceImpl<SectionMapper, Section> implements ISectionService {

    @Autowired
    SectionMapper sectionMapper;
    @Override
    public IPage<Map<String, Object>> getorgandsection(Map<String, Object> map) {
        Page page = new Page(Integer.parseInt(map.get("page").toString()),Integer.parseInt(map.get("count").toString()));
        QueryWrapper queryWrapper = new QueryWrapper();
        Set<String> keys = map.keySet();
        for (String key : keys) {
            if("page".equals(key) || "count".equals(key))
                continue;
            else
                queryWrapper.eq(key,map.get(key));
        }

        return sectionMapper.getorgandsection(page,queryWrapper);
    }

    @Override
    public IPage<Map<String, Object>> getbyorgidanddivname(Map<String, Object> map) {
        Page page = new Page(Integer.parseInt(map.get("page").toString()),Integer.parseInt(map.get("count").toString()));
        QueryWrapper queryWrapper = new QueryWrapper();
        Set<String> keys = map.keySet();
        for (String key : keys) {
            if("page".equals(key) || "count".equals(key)){
                continue;
            }else if("orgId".equals(key) || "divName".equals(key)){
                queryWrapper.like(key,map.get(key));
            }
        }
        return sectionMapper.getorgidanddivname(page,queryWrapper);
    }
}
